<?php

require_once dirname(__FILE__) . '/../../../Domain51UnitTest.config.php';
require_once 'Domain51/Util/String/Hex.php';
require_once 'Domain51/Util/String.php';

class Domain51_Util_String_HexTest extends PHPUnit_Framework_TestCase
{
    public function testTurnsHexToRawDecimal() {
        $random = 'ABC' . rand(1000, 2000) . 'XYZ';
        
        $hex = new Domain51_Util_String_Hex();
        $result = $hex->toDecimal($random);
        
        $expected = hexdec($random);
        $this->assertSame($expected, $result);
    }
    
    public function testConvertsRawHexStringToBase64() {
        $random = 'ffaa' . rand(10, 99);
        
        $hex = new Domain51_Util_String_Hex();
        $result = $hex->toBase64($random);
        
        $string = new Domain51_Util_String();
        $raw = '';
        for($i = 0; $i < strlen($random); $i += 2) {
            $raw .= $string->charFromInt($hex->toDecimal(substr($random, $i, 2)));
        }
        $expected = base64_encode($raw);
        
        $this->assertSame($expected, $result); 
    }
}

?>